package com.atming.zuul.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Component
public class CustomFilter extends ZuulFilter {

    //public  static final Logger logger=LoggerFactory.getLogger(CustomFilter.class);
    //过滤类型
    @Override
    public String filterType() {
        return "pre";
    }

    //执行顺序  小 高
    @Override
    public int filterOrder() {
        return 0;
    }

    // 执行条件 true开启
    @Override
    public boolean shouldFilter() {
        return true;
    }

    //动作  具体逻辑
    @Override
    public Object run() throws ZuulException {
        RequestContext rc=RequestContext.getCurrentContext();
        HttpServletRequest request = rc.getRequest();
        log.info("CustomerFilter...method={},url={}", request.getMethod(),request.getRequestURL().toString());
        return null;
    }
}
